package cn.iocoder.yudao.module.yyzx.service.check_In;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.yyzx.controller.admin.check_In.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.check_In.Check_InDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.yyzx.dal.mysql.check_In.Check_InMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.*;

/**
 * 入住登记 Service 实现类
 *
 * @author w
 */
@Service
@Validated
public class Check_InServiceImpl implements Check_InService {

    @Resource
    private Check_InMapper check_InMapper;

    @Override
    public Integer createCheck_In(Check_InSaveReqVO createReqVO) {
        // 插入
        Check_InDO check_In = BeanUtils.toBean(createReqVO, Check_InDO.class);
        check_InMapper.insert(check_In);
        // 返回
        return check_In.getId();
    }

    @Override
    public void updateCheck_In(Check_InSaveReqVO updateReqVO) {
        // 校验存在
        validateCheck_InExists(updateReqVO.getId());
        // 更新
        Check_InDO updateObj = BeanUtils.toBean(updateReqVO, Check_InDO.class);
        check_InMapper.updateById(updateObj);
    }

    @Override
    public void deleteCheck_In(Integer id) {
        // 校验存在
        validateCheck_InExists(id);
        // 删除
        check_InMapper.deleteById(id);
    }

    private void validateCheck_InExists(Integer id) {
        if (check_InMapper.selectById(id) == null) {
            throw exception(CHECK_IN_NOT_EXISTS);
        }
    }

    @Override
    public Check_InDO getCheck_In(Integer id) {
        return check_InMapper.selectById(id);
    }

    @Override
    public PageResult<Check_InDO> getCheck_InPage(Check_InPageReqVO pageReqVO) {
        return check_InMapper.selectPage(pageReqVO);
    }

}